package org.vy.dal.dao.admin;

import org.vy.dal.QueryManager;

public class VyAdmModulesDAO {
	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE MODULE_CODE = m_moduleCode";
	private static final String UPDATE = "UPDATE <TABLE> SET MODULE_NAME = m_moduleName, MODULE_DESC = m_moduleDesc, IS_ACTIVE = m_isActive, LAST_UPDATED_BY = m_lastUpdatedBy, LAST_UPDATED_ON = m_lastUpdatedOn WHERE MODULE_CODE = m_moduleCode";
	private static final String INSERT = "INSERT INTO <TABLE> (MODULE_CODE,MODULE_NAME,MODULE_DESC,IS_ACTIVE,LAST_UPDATED_BY,LAST_UPDATED_ON) VALUES(m_moduleCode,m_moduleName,m_moduleDesc,m_isActive,m_lastUpdatedBy,m_lastUpdatedOn)";
	private static final String DELETE = "DELETE FROM <TABLE> WHERE MODULE_CODE = m_moduleCode";

	public static VyAdmModulesDO findByPK(String key) throws Exception {
		VyAdmModulesDO dto = new VyAdmModulesDO();
		dto.setModuleCode(key);
		dto = (VyAdmModulesDO) QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}
	public static VyAdmModulesDO insert(VyAdmModulesDO dto) throws Exception {

		dto = (VyAdmModulesDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyAdmModulesDO update(VyAdmModulesDO dto) throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static VyAdmModulesDO delete(String key) throws Exception {
		VyAdmModulesDO dto = new VyAdmModulesDO();
		dto.setModuleCode(key);
		boolean i = QueryManager.executeDelete(dto, DELETE);
		if (i == true)
			return dto;
		else
			return null;
	}

}
